package com.ax.api.route.business.hemp;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.ax.api.route.util.RouteConfig;

@RestController
@RequestMapping("/hemp")
public class HempRoute {
	@Autowired
    LoadBalancerClient loadBalancerClient;
    @Autowired
    RestTemplate restTemplate;
    
    
    /**
	 * insertHemp
	 * remote_bussiness
	 * 新增含麻登记
	 */   
	@GetMapping("/insertHemp")
	public String insertHemp(@RequestParam Map<String,Object> map){
		String value = "?hempRegisteSeq={hempRegisteSeq}&hempRegisteSeq={hempRegisteSeq}&associatorId={associatorId}&associatorName={associatorName}&personId={personId}&patientPhone={patientPhone}&sourceSeq={sourceSeq}&flag={flag}";
		String url = geturl("/insertHemp")+value;
		return restTemplate.getForObject(url,String.class,map);
		
  }
	/**
	 * insertHemp
	 * remote_bussiness
	 * 查询含麻登记
	 */   
	@GetMapping("/queryHemp")
	public String queryHemp(@RequestParam Map<String,Object> map){
		String value = "?hempRegisteSeq={hempRegisteSeq}&hempRegisteSeq={hempRegisteSeq}&personId={personId}&patientPhone={patientPhone}&sourceSeq={sourceSeq}&flag={flag}";
		String url = geturl("/queryHemp")+value;
		return restTemplate.getForObject(url,String.class,map);
		
  }
	   private String geturl(String path){
		 ServiceInstance serviceInstance = loadBalancerClient.choose(RouteConfig.BUSSINESS_ROUTE);
		 StringBuffer bf = new StringBuffer("http://");
		 bf.append(serviceInstance.getHost());
		 bf.append(":");
		 bf.append(serviceInstance.getPort());
		 bf.append(path);
		 return bf.toString();
		   
	   }
}
